#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = (1 << 22) + 5;

int J[2][N], O[2][N], I[2][N], F[2][N], pw[30];
int K, n, tn;
char s[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = 1 << (2 * (K = in)); tn = n << 1; scanf("%s",s + 1); rep(i, 1, n) s[i + n] = s[i];
	memset(F, 0x3f, sizeof F); 
	rep(i, 1, tn) {
		J[0][i] = s[i] != 'J'; O[0][i] = s[i] != 'O'; I[0][i] = s[i] != 'I'; F[0][i] = 0;
	}
	pw[0] = 1; rep(i, 1, K) pw[i] = pw[i - 1] * 4;
	int o = 0; 
	rep(i, 1, K) {
		rep(j, 1, tn - pw[i - 1] + 1) {
			J[o ^ 1][j] = J[o][j] + J[o][j + pw[i - 1]] + J[o][j + pw[i - 1] * 2] + J[o][j + pw[i - 1] * 3];
			O[o ^ 1][j] = O[o][j] + O[o][j + pw[i - 1]] + O[o][j + pw[i - 1] * 2] + O[o][j + pw[i - 1] * 3];
			I[o ^ 1][j] = I[o][j] + I[o][j + pw[i - 1]] + I[o][j + pw[i - 1] * 2] + I[o][j + pw[i - 1] * 3];
			F[o ^ 1][j] = J[o][j] + O[o][j + pw[i - 1]] + I[o][j + pw[i - 1] * 2] + F[o][j + pw[i - 1] * 3];
		} o ^= 1;
	}
	int ans = n + 1;
	rep(i, 1, n) ans = min(ans, F[o][i]);
	cout << ans << endl;
	return 0;
}
